package cn.wolfcode.p2p.website.controller;

import cn.wolfcode.p2p.base.qo.BidRequestQueryObject;
import cn.wolfcode.p2p.base.qo.TransferCreditQueryObject;
import cn.wolfcode.p2p.base.util.Constants;
import cn.wolfcode.p2p.business.service.IBidRequestService;
import cn.wolfcode.p2p.business.service.ICreditTransferService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class InvestController {
    @Autowired
    private IBidRequestService bidRequestService;
    @Autowired
    private ICreditTransferService creditTransferService;

    @RequestMapping("/invest")
    public String investPage(){
        return "invest";
    }
    @RequestMapping("/invest_list")
    public String investListPage(BidRequestQueryObject qo, Model model){
        //信用标
        if (qo.getBidRequestType() == Constants.BIDREQUEST_TYPE_NORMAL) {
            qo.setStates(new int[]{Constants.BIDREQUEST_STATE_BIDDING, Constants.BIDREQUEST_STATE_PAYING_BACK, Constants.BIDREQUEST_STATE_COMPLETE_PAY_BACK});
            qo.setOrderByCondition(" b.bidRequestState asc"); //招标中,还款中,已还清 顺序排列
            PageInfo pageInfo = bidRequestService.queryPage(qo);
            model.addAttribute("pageInfo", pageInfo);
            return "invest_list";
        } else {
            //债权转让标
            TransferCreditQueryObject cto = new TransferCreditQueryObject();
            cto.setPageNum(qo.getPageNum());
            cto.setPageSize(qo.getPageSize());
            cto.setState(Constants.BIDREQUEST_STATE_BIDDING);
            model.addAttribute("pageInfo", creditTransferService.queryPage(cto));
            return "credittransfer_list";
        }
    }
}
